Skip to content

Conversation

@juskeeratanand
Copy link
Contributor

@juskeeratanand juskeeratanand commented Sep 25, 2025

This PR implements the work done here to add the ability to authenticate against AWS in the python client.

This is done by the client using AWS credentials to sign a request to GetCallerIdentity and then sending that signed proof to Datadog for validation. Read more about this process here. In this PR, we add the proof generation to the datadog client and add the ability to pass that token on subsequent requests.

@juskeeratanand juskeeratanand changed the title changed template files + generate [DELA-208] Adding delegated token authentication in python client Sep 25, 2025
@juskeeratanand juskeeratanand marked this pull request as ready for review September 29, 2025 20:27
@juskeeratanand juskeeratanand requested review from a team as code owners September 29, 2025 20:27
@juskeeratanand juskeeratanand requested a review from a team September 29, 2025 20:47
@juskeeratanand juskeeratanand marked this pull request as draft September 30, 2025 17:33
@juskeeratanand juskeeratanand marked this pull request as ready for review September 30, 2025 18:28
Copy link
Contributor

@urnfdog urnfdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP, just a couple comments.

:param headers: Header parameters dict to be updated.
:raises: ApiValueError if delegated token authentication fails
"""
from datetime import datetime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: Is this necessary, or can it be rolled up into a more global import?

:return: User agent string
"""
import platform
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: Do we need this import at the function level?

Comment on lines 465 to 467
# Check if we have cached credentials
if not hasattr(self.configuration, "_delegated_token_credentials"):
self.configuration._delegated_token_credentials = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Check if we have cached credentials
if not hasattr(self.configuration, "_delegated_token_credentials"):
self.configuration._delegated_token_credentials = None

Looks like this variable is already initialized as None.

Comment on lines 347 to 350
# Delegated token configuration
self.delegated_token_config = None

# Load default values from environment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like constructors are missing in the config for fields such as delegated_auth_provider and delegated_auth_org_uuid

Comment on lines 475 to 479
config = DelegatedTokenConfig(
org_uuid=self.configuration.delegated_auth_org_uuid,
provider="aws", # This could be made configurable
provider_auth=self.configuration.delegated_auth_provider,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how often the token refreshes but we should move this up to class initialization as it seems to be a static config for the most part.

url = get_delegated_token_url(config)

# Create REST client
rest_client = rest.RESTClientObject(config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pass the rest client initialized in the api_client? If not we should initialize this once and store it for future use

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Oct 22, 2025
Copy link
Contributor

@urnfdog urnfdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming that signing mechanisms (especially HMAC) are all taken directly from AWS specs

"""
try:
token_response = json.loads(response_data)
except json.JSONDecodeError as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 Do we need to catch other kinds of errors here, and is there a reason we handle JSONDecodeError specifically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this catches when the json parsing fails which would be the most expected error, and any other errors would be caught by the outer block

"""
try:
token_response = json.loads(response_data)
except json.JSONDecodeError as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar question around if we need to handle other types of errors

Comment on lines +130 to +132
"AWS_ACCESS_KEY_ID": "AKIAIOSFODNN7EXAMPLE",
"AWS_SECRET_ACCESS_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"AWS_SESSION_TOKEN": "test-session-token",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: These are the example access key values from AWS docs, including GetAccessKeyInfo

juskeeratanand and others added 3 commits October 27, 2025 15:28
Co-authored-by: Kevin L <96131879+urnfdog@users.noreply.github.com>
Co-authored-by: Kevin L <96131879+urnfdog@users.noreply.github.com>
@juskeeratanand
Copy link
Contributor Author

/merge

@dd-devflow-routing-codex
Copy link

dd-devflow-routing-codex bot commented Nov 3, 2025

View all feedbacks in Devflow UI.

2025-11-03 15:39:34 UTC ℹ️ Start processing command /merge


2025-11-03 15:39:42 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2025-11-03 16:20:54 UTC ⚠️ MergeQueue: This merge request was unqueued

juskeerat.anand@datadoghq.com unqueued this merge request

@juskeeratanand
Copy link
Contributor Author

/remove

@dd-devflow-routing-codex
Copy link

dd-devflow-routing-codex bot commented Nov 3, 2025

View all feedbacks in Devflow UI.

2025-11-03 16:20:48 UTC ℹ️ Start processing command /remove


2025-11-03 16:20:51 UTC ℹ️ Devflow: /remove

@juskeeratanand
Copy link
Contributor Author

/merge

@dd-devflow-routing-codex

This comment was marked as outdated.

@juskeeratanand
Copy link
Contributor Author

/remove

@dd-devflow-routing-codex
Copy link

dd-devflow-routing-codex bot commented Nov 3, 2025

View all feedbacks in Devflow UI.

2025-11-03 16:23:00 UTC ℹ️ Start processing command /remove


2025-11-03 16:23:03 UTC ℹ️ Devflow: /remove

@juskeeratanand
Copy link
Contributor Author

/merge

@dd-devflow-routing-codex
Copy link

dd-devflow-routing-codex bot commented Nov 3, 2025

View all feedbacks in Devflow UI.

2025-11-03 16:26:20 UTC ℹ️ Start processing command /merge


2025-11-03 16:26:28 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2025-11-03 16:31:31 UTC ℹ️ MergeQueue: This merge request was already merged

This pull request was merged directly.

@skarimo skarimo merged commit cb28bb6 into master Nov 3, 2025
35 checks passed
@skarimo skarimo deleted the DELA-208 branch November 3, 2025 16:31
github-actions bot pushed a commit that referenced this pull request Nov 3, 2025
)

* changed template files + generate

* rename file

* rename files to match go client

* fix aws tests

* fix conftest

* Restore docs/datadog_api_client.rst file

* regen

* print header

* fix headers

* fix config propogation

* feedback updates

* rest changes

* gen

* update

* del

* fix tests

* static config

* update config

* updates tests

* update imports

* config

* Update src/datadog_api_client/api_client.py

Co-authored-by: Kevin L <96131879+urnfdog@users.noreply.github.com>

* Update src/datadog_api_client/api_client.py

Co-authored-by: Kevin L <96131879+urnfdog@users.noreply.github.com>

* pre-commit fixes

---------

Co-authored-by: Kevin L <96131879+urnfdog@users.noreply.github.com>
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com> cb28bb6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Added documentation Improvements or additions to documentation mergequeue-status: done

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants